07. Matrix Multiplication - General

So far we only concentrated on square matrix multiplications. However, we are not limited to square matrices alone.

Lets look again at our image that represents the multiplication PP x QQ:

Remember, the order here does matter, as matrix multiplication is not commutative

If you look closely at the image that represents the multiplication of PP x QQ, you will see that the number columns in PP equals the number of rows in QQ. (In the case of our example, it was 33 ).

How many rows do we have in matrix PP? How many columns do we have in matrix QQ? That will deretmine the dimensions of the resulting multiplication.

In other words, if PP is a matrix with dimensions tt x mm and QQ is a matrix with dimensions mm x vv then:

  • PPxQQ is possible as the dimensions match. (PP has mm columns and QQ has mm rows).

  • PPxQQ will be a matrix of ttxvv. (tt rows and vv columns).

Lets look at an example:

P=[p11p12p13p21p22p23]P=\begin{bmatrix} p_{11} &p_{12} &p_{13}\\ p_{21} &p_{22} &p_{23}\end{bmatrix}

Q=[q11q12q13q14q21q22q23q24q31q32q33q34]Q=\begin{bmatrix} q_{11} &q_{12}&q_{13}&q_{14}\\ q_{21} &q_{22}&q_{23}&q_{24} \\q_{31} &q_{32}&q_{33}&q_{34}\end{bmatrix}

We would like to calculate PPxQQ.

Our first step is to see if the calculation is possible. We will do that by looking at the dimensions of the matrices.

Matrix PP has 33 columns and matrix QQ has 33 rows. Perfect! multiplication is possible.

We expect to have a final result PPxQQ with the dimensions 22x44 (22 rows and 44 columns).

PPxQQ= [p11q11+p12q21+p13q31p11q12+p12q22+p13q32p11q13+p12q23+p13q33p11q14+p12q24+p13q34p21q11+p22q21+p23q31p21q12+p22q22+p23q32p21q13+p22q23+p23q33p21q14+p22q24+p23q34]\begin{bmatrix} p_{11}q_{11}+p_{12}q_{21}+p_{13}q_{31} &p_{11}q_{12}+p_{12}q_{22}+p_{13}q_{32} &p_{11}q_{13}+p_{12}q_{23}+p_{13}q_{33} &p_{11}q_{14}+p_{12}q_{24}+p_{13}q_{34}\\ p_{21}q_{11}+p_{22}q_{21}+p_{23}q_{31} &p_{21}q_{12}+p_{22}q_{22}+p_{23}q_{32} &p_{21}q_{13}+p_{22}q_{23}+p_{23}q_{33}&p_{21}q_{14}+p_{22}q_{24}+p_{23}q_{34}\end{bmatrix}

Equation 16